﻿using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace App.UI
{
    internal class Table<T> : DataGridView
    {

        public Table()
        {
            Dock = DockStyle.Fill;
            this.AllowUserToAddRows = false;
            this.AllowUserToDeleteRows = false;
            this.AllowUserToOrderColumns = true;
            this.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            this.ReadOnly = true;
            this.RowHeadersVisible = false;
            this.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            this.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
        }

        public void SetHeader(string[] headers)
        {
            this.Columns.Clear();
            foreach (string header in headers)
            {
                DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn
                {
                    HeaderText = header,
                    Name = header,
                    SortMode = DataGridViewColumnSortMode.NotSortable 
                };
                this.Columns.Add(column);
            }
        }



        public void SetData(T[][] data)
        {
            this.Rows.Clear();
            foreach (T[] row in data)
            {
                object[] rowData = row.Cast<object>().ToArray();
                this.Rows.Add(rowData);
            }
        }

    }
}
